package com.qdxy.app.lhjh.activities;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

import com.lf.tempcore.tempActivity.TempActivity;
import com.lf.tempcore.tempModule.tempDebuger.Debug;
import com.qdxy.app.lhjh.R;
import com.qdxy.app.lhjh.activities.fragments.FragJiaGong2;
import com.qdxy.app.lhjh.activities.fragments.FragTouLiaoV2;
import com.qdxy.app.lhjh.activities.fragments.FragZhuangXiang;
import com.qdxy.app.lhjh.adapters.ActProductionTabAdapter;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by KY on 2016/10/8.
 * 生产加工
 */

public class ActProduction extends TempActivity {
    private final String TAG = ActProduction.class.getSimpleName();

    @Override
    protected void initContentView(Bundle savedInstanceState) {
        setContentView(R.layout.act_production_layout);

    }

    @Override
    protected void findViews() {
        Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
        initToolbar(toolbarTop, "产品加工");
//        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//        getSupportActionBar().setDisplayShowTitleEnabled(true);
        List<String> tabs = new ArrayList<>();
        tabs.add("投料");
        tabs.add("加工");
        tabs.add("装箱");
        TabLayout tablayout = (TabLayout) findViewById(R.id.act_production_TabLayout);
        ViewPager viewPager = (ViewPager) findViewById(R.id.act_production_ViewPager);
        initTabs(tablayout, viewPager, tabs);
    }

    @Override
    protected void setListeners() {

    }

    @Override
    protected void bindValues() {

    }

    @Override
    protected void OnViewClicked(View v) {

    }

    /**
     * @param item
     * @return
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Debug.info(TAG, "进入action点击" + item.getItemId());
        if (item.getItemId() == android.R.id.home) {
            Debug.info(TAG, "返回按钮点击");
        }
        return super.onOptionsItemSelected(item);
    }

    private void initTabs(TabLayout tabLayout, ViewPager viewPager, List<String> tabs) {
        tabLayout.removeAllTabs();
        viewPager.removeAllViews();

        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        List<Fragment> fragmentList = new ArrayList<>();

        for (int i = 0; i < tabs.size(); i++) {
            tabLayout.addTab(tabLayout.newTab().setText(tabs.get(i)));
            if (tabs.get(i).equals("投料")) {
                fragmentList.add(new FragTouLiaoV2());
            } else if (tabs.get(i).equals("加工")) {
                fragmentList.add(new FragJiaGong2());
            } else if (tabs.get(i).equals("装箱")) {
                fragmentList.add(new FragZhuangXiang());
            }
        }

        ActProductionTabAdapter adapter = new ActProductionTabAdapter(getSupportFragmentManager(), fragmentList, tabs);
        viewPager.setAdapter(adapter);//给ViewPager设置适配器
        tabLayout.setupWithViewPager(viewPager);//将TabLayout和ViewPager关联起来。
        tabLayout.setTabsFromPagerAdapter(adapter);//给Tabs设置适配器
    }
}
